package com.ruoyi.purchase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.purchase.vo.InspectionPlanVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.purchase.domain.InspectionPlan;
import com.ruoyi.purchase.service.IInspectionPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收料检验计划Controller
 * 
 * @author ruoyi
 * @date 2025-10-31
 */
@RestController
@RequestMapping("/purchase/plan")
public class InspectionPlanController extends BaseController
{
    @Autowired
    private IInspectionPlanService inspectionPlanService;


    /**
     * 更新拒收状态
     */
    @PreAuthorize("@ss.hasPermi('purchase:inspectionPlan:edit')")
    @Log(title = "收料检验计划", businessType = BusinessType.UPDATE)
    @PutMapping("/updateRejectStatus/{id}")
    public AjaxResult updateRejectStatus(@PathVariable Long id, @RequestParam Long rejectStatus) {
        return inspectionPlanService.updateRejectStatus(id, rejectStatus);
    }

    /**
     * 查询收料检验计划列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectionPlanVO inspectionPlanVO)
    {
        startPage();
        List<InspectionPlanVO> list = inspectionPlanService.selectInspectionPlanVOList(inspectionPlanVO);
        System.out.println("计划返回"+list);
        return getDataTable(list);
    }

    /**
     * 导出收料检验计划列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:plan:export')")
    @Log(title = "收料检验计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionPlan inspectionPlan)
    {
        List<InspectionPlan> list = inspectionPlanService.selectInspectionPlanList(inspectionPlan);
        ExcelUtil<InspectionPlan> util = new ExcelUtil<InspectionPlan>(InspectionPlan.class);
        util.exportExcel(response, list, "收料检验计划数据");
    }

    /**
     * 获取收料检验计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        System.out.println("一条检验数据"+inspectionPlanService.selectInspectionPlanVOById(id));
        return success(inspectionPlanService.selectInspectionPlanVOById(id));
    }

    /**
     * 新增收料检验计划
     */
    @PreAuthorize("@ss.hasPermi('purchase:plan:add')")
    @Log(title = "收料检验计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionPlan inspectionPlan)
    {
        return toAjax(inspectionPlanService.insertInspectionPlan(inspectionPlan));
    }

    /**
     * 修改收料检验计划
     */
    @PreAuthorize("@ss.hasPermi('purchase:plan:edit')")
    @Log(title = "收料检验计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionPlan inspectionPlan)
    {
        return toAjax(inspectionPlanService.updateInspectionPlan(inspectionPlan));
    }

    /**
     * 删除收料检验计划
     */
    @PreAuthorize("@ss.hasPermi('purchase:plan:remove')")
    @Log(title = "收料检验计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inspectionPlanService.deleteInspectionPlanByIds(ids));
    }
}
